package Exercise06;

public class Test {
    public static void main(String[] args) {
        Student student = new Student("jack", 12, '男', "001244");
        student.printInfo();

        System.out.println("==================");
        Teacher teacher = new Teacher("lihua", 56, '女', 32);
        teacher.printInfo();


        Person person[] = new Person[4];
        person[0] = new Student("jack", 18, '男', "0001");
        person[1] = new Student("lihua", 22, '女', "0002");
        person[2] = new Teacher("jack", 36, '男', 15);
        person[3] = new Teacher("jack", 59, '男', 26);

        Test test = new Test();
        test.bubble(person);
        for (int i = 0; i < person.length; i++) {
            System.out.println(person[i]);
        }
        System.out.println("=====================");
        for (int i = 0; i < person.length; i++) {
            test.test(person[i]);
        }

    }
    public void test(Person p){
    if(p instanceof Student){
        ((Student) p).study();
    }
    else if(p instanceof  Teacher){
        ((Teacher) p).teach();
    }
    else {
        System.out.println("类型错误");
    }
    }

    public void bubble(Person person[]) {
        for (int i = 0; i < person.length - 1; i++) {

            for (int j = 0; j < person.length - i - 1; j++) {
                if (person[j].getAge() < person[j + 1].getAge()) {
                    Person tmp = person[j];
                    person[j] = person[j + 1];
                    person[j + 1] = tmp;
                }

            }
        }

    }
}
